﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class KhuyenMaiDAO
    {

        public static double TimKMthoa()
        {
            try
            {
                QLSTLinqDataContext rv = new QLSTLinqDataContext();

                List<HangHoa> ds = new List<HangHoa>();
                var query = (from c in rv.KhuyenMais
                            where c.NgayApDung <= DateTime.Now && c.NgayKetThuc >= DateTime.Now
                            select c).First();
                double km = (double)query.PhanTramGiam;

                return km;
            }
            catch
            {
                return 0.0;
            }
        }

        public static bool Them(KhuyenMai aCT)
        {
            try
            {
                QLSTLinqDataContext rv = new QLSTLinqDataContext();
                rv.KhuyenMais.InsertOnSubmit(aCT);
                rv.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
